<?php

require_once("includes/sparqllib.php");
require_once("model/QueryManager.class.php");
Class measureController Extends baseController {

public function index() 
{
       
        $this->registry->template->show('measure_index');
		
		
}


public function view(){
   
        $this->queryManager=QueryManager::GetInstance();
       $this->queryManager->iniConnection($this->parameters['endpoint']);
      
        $measure=$this->getMeasureMetadata($this->parameters['uri']);
      if(isset($measure)){
			 echo '{"status":"ok","measure":'.json_encode($measure).'}';
        }
        else{ 
          echo '{"status":"error","msg":"No dimension exists..."}';
 		 }    
       
        
}

public function tooltip(){
   
        $this->queryManager=QueryManager::GetInstance();
       $this->queryManager->iniConnection($this->parameters['endpoint']);
      
        $measure=$this->getMeasureMetadata($this->parameters['uri']);
         

  if(isset($measure)){
         $this->registry->template->measure=$measure;
		 $this->registry->template->endpoint=$this->parameters['endpoint'];
			 
        }
        else{ 
         $this->registry->template->measure=null;
 		 }     
      $this->registry->template->show('measure_tooltip');
       
        
}

public function getMeasureMetadata($measure_uri){


		$this->queryManager=QueryManager::GetInstance();
 		$sparql=$this->queryManager->getMeasureMetadataQuery($measure_uri);
	   	$result = sparql_query( $sparql ); 
		if( !$result ) { print sparql_errno() . ": " . sparql_error(). "\n"; exit; }
		$measure=null;
		while($row = sparql_fetch_array( $result )){
		$label=(isset($row['measureLabel'])) ? $row['measureLabel'] : "N/A";   ;
		$comment=(isset($row['comment'])) ? $row['comment'] : "no data available";
		$measure=Measure::WrapMeasure($label ,$measure_uri ,$comment);
		}
	return $measure;

}

}
?>
